package com.heer.gymnasium.util;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;

import com.heer.gymnasium.callback.I_SkipActivity;

/**
 * Created by heer on 17/3/30.
 */

public class ActivityStartUtils implements I_SkipActivity {

    private Activity mActivity;

    public ActivityStartUtils(Activity mActivity) {
        this.mActivity = mActivity;
    }

    /**
     * 指定Activity跳转，不带参数
     *
     * @param claz 组件名
     */
    protected void jump(Class<? extends Activity> claz) {
        jump(claz, null);
    }

    /**
     * 指定Activity跳转，带参数
     *
     * @param claz 组件名
     * @param data 参数
     */
    protected void jump(Class<? extends Activity> claz, Bundle data) {
        Intent intent = new Intent(mActivity, claz);
        if (data != null) {
            intent.putExtras(data);
        }
        mActivity.startActivity(intent);
    }


    @Override
    public void skipActivity(Class<?> cls) {
        skipActivity(mActivity, cls);
    }

    /**
     * skip to @param(cls)，and call @param(aty's) finish() method
     */
    @Override
    public void skipActivity(Activity aty, Class<?> cls) {
        showActivity(aty, cls);
        aty.finish();
    }

    /**
     * skip to @param(cls)，and call @param(aty's) finish() method
     */
    @Override
    public void skipActivity(Activity aty, Intent it) {
        showActivity(aty, it);
        aty.finish();
    }

    /**
     * skip to @param(cls)，and call @param(aty's) finish() method
     */
    @Override
    public void skipActivity(Activity aty, Class<?> cls, Bundle extras) {
        showActivity(aty, cls, extras);
        aty.finish();
    }

    @Override
    public void showActivity(Class<?> cls) {
        showActivity(mActivity, cls);
    }

    /**
     * show to @param(cls)，but can't finish activity
     */
    @Override
    public void showActivity(Activity aty, Class<?> cls) {
        Intent intent = new Intent();
        intent.setClass(aty, cls);
        aty.startActivity(intent);
    }

    /**
     * show to @param(cls)，but can't finish activity
     */
    @Override
    public void showActivity(Activity aty, Intent it) {
        aty.startActivity(it);
    }

    /**
     * show to @param(cls)，but can't finish activity
     */
    @Override
    public void showActivity(Activity aty, Class<?> cls, Bundle extras) {
        Intent intent = new Intent();
        intent.putExtras(extras);
        intent.setClass(aty, cls);
        aty.startActivity(intent);
    }
}
